﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
using HRProject.Code.DTO;
using HRProject.Code.DAO;
using HRProject.Code.Common;

namespace HRProject.User
{
    public partial class TaskStatistics : System.Web.UI.Page
    {
        private List<BLTaskStatistics> listStatistics;
        private int maxTotalInEachRecord = 0;
        private int year;

        public int Year
        {
            get { return year; }
            set { year = value; }
        }
        private Guid userId;

        public Guid UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        public int MaxTotalInEachRecord
        {
            get { return maxTotalInEachRecord; }
            set { maxTotalInEachRecord = value; }
        }

        public List<BLTaskStatistics> ListStatistics
        {
            get { return listStatistics; }
            set { listStatistics = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                userId = new Guid(Request.Params["userId"]);
            }
            catch (Exception exp)
            {
                MembershipUser user = Membership.GetUser();
                if (user != null)
                    userId = (Guid)user.ProviderUserKey;
                else
                    userId = Guid.Empty;
                Console.Out.WriteLine(exp.Message);
            }
            if (!userId.Equals(Guid.Empty))
            {
                TaskDAO dao = new TaskDAO();
                year = DateTime.Now.Year;
                int temp;
                if (int.TryParse(Request.Params["year"], out temp))
                {
                    if (temp > Constant.DefaultMinDate.Year && temp < Constant.DefaultMaxDate.Year)
                        year = temp;
                }
                listStatistics = dao.makeStatistics(userId, year, out maxTotalInEachRecord);
            }
            else
            {
                listStatistics = new List<BLTaskStatistics>();
            }
        }
    }
}
